package com.aixin.project.util;

import com.aixin.project.data.AxSession;
import com.aixin.project.data.CommonConstants;
import org.apache.commons.codec.binary.Base64;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA.
 * User: Sufeng
 * Date: 12-5-16
 * Time: 下午11:32
 * To change this template use File | Settings | File Templates.
 */
public class AxUtil {
    private static Base64 base64 = new Base64();
    private static ThreadLocal<HttpServletRequest> threadLocalRequest = new ThreadLocal<HttpServletRequest>();
    private static ThreadLocal<AxSession> threadLocalAxSession = new ThreadLocal<AxSession>();

    public static long getGenseeUid(long courseid,long userid){
        String key = CommonConstants.MKEY_LIVEBROAD_GENSEEUID+courseid+"_"+userid;
        AxMemcached.get(key);
        return 0;
    }

    public static long getGenseeUidCounter(){
        return CommonConstants.GENSEE_BASE_ID+AxMemcached.getCounter(CommonConstants.MKEY_GENSEEUID_COUNTER);
    }

    public static HttpServletRequest getRequest() {
        return threadLocalRequest.get();
    }

    public static void setThreadLocalRequest(HttpServletRequest request) {
        threadLocalRequest.set(request);
    }

    public static AxSession getAxSession() {
        return threadLocalAxSession.get();
    }

    public static void setThreadLocalAxSession(AxSession axSession) {
        threadLocalAxSession.set(axSession);
    }
    
    public static String base64Encode(String str){
        return new String(base64.encode(str.getBytes()));
    }
    
    public static String base64Decode(String str){
        return new String(base64.decode(str.getBytes()));
    }
}
